<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.js"></script>
  </head>
  <!-- 说明计算是有缓存优化的，多次调用实际上只是计算了1次，但是methods每次调用都会重新执行
  出于性能考虑，应该优先使用计算属性 -->
  <body>
    <div id="app">
      <h2>{{fullName}} </h2>
      <h2>{{fullName}} </h2>
      <h2>{{fullName}} </h2>
      <h2> {{getFullName()}}</h2>
      <h2> {{getFullName()}}</h2>
      <h2> {{getFullName()}}</h2>
    </div>
    <script>
      var vm = new Vue({
        el: "#app",
        data: {
          firstName: "Wang",
          lastName: "ZhiYuan",
        },
        methods: {
          getFullName() {
            console.log("methods方法被调用了");
            return this.firstName + this.lastName;
          },
        },
        computed: {
          fullName() {
            console.log("计算属性被调用了");
            return this.firstName + this.lastName;
          },
        },
      });
    </script>
  </body>
</html>
